package cn.itcast.tools.java调用shell;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class Test {
    public static void main(String[] args) {
        List<String> commend = new ArrayList<String>();
        commend.add("/usr/local/ffmpeg2/bin/./ffmpeg");
        commend.add("-i");
        commend.add("/opt/spzh/yysp.avi");
        commend.add("-ab");
        commend.add("128");
        commend.add("-acodec");
        commend.add("libfaac");
        commend.add("-ac");
        commend.add("1");
        commend.add("-ar");
        commend.add("22050");
        commend.add("-r");
        commend.add("24");
        commend.add("-y");
        commend.add("/opt/spzh/out/yysp18.flv");
        StringBuffer test=new StringBuffer();
        for(int i=0;i<commend.size();i++)
            test.append(commend.get(i)+" ");
        System.out.println(test);
        try {
            Runtime rt = Runtime.getRuntime();
            Process proc = rt.exec(test.toString());
            InputStream stderr = proc.getErrorStream();
            InputStreamReader isr = new InputStreamReader(stderr);
            BufferedReader br = new BufferedReader(isr);
            String line = null;
            while ( (line = br.readLine()) != null);

        } catch (IOException e) {
            e.printStackTrace();
        }
        System.out.println("视频转换成功");
    }
}
